package org.wendu.wdoa.service.impl;

import org.wendu.wdoa.common.CurrentUser;
import org.wendu.wdoa.dao.LoginDao;
import org.wendu.wdoa.dto.LoginDto;
import org.wendu.wdoa.exception.BusinessException;
import org.wendu.wdoa.model.User;
import org.wendu.wdoa.service.LoginService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class LoginServiceImpl implements LoginService {

    @Resource
    private LoginDao loginDao;


    @Override
    public CurrentUser checkLogin(LoginDto dto) {
        User user = loginDao.findUserByUserIdAndPwd(dto);
        if (user == null){
            throw new BusinessException("账号或密码错误");
        }
        CurrentUser currentUser = new CurrentUser();
        currentUser.setUserId(user.getU_id());
        currentUser.setUserName(user.getU_name());
        return currentUser;

    }
}
